package cn.xf;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class Test002 {

    public static void main(String[] args) {
        User user = new JSONObject().parseObject(getString(), User.class);
        System.out.println("user:" + user.toString());
    }


    public static String getString(){
        // 1.json api 封装json
        JSONObject root = new JSONObject();
        root.put("id", "01");
        root.put("name", "张三");
        JSONArray arrayList = new JSONArray();
        JSONObject object1 = new JSONObject();
        object1.put("itemId", "20");
        object1.put("itemName", "蚂蚁课堂");
        JSONObject object2 = new JSONObject();
        object2.put("itemId", "30");
        object2.put("itemName", "每特学院");
        arrayList.add(object1);
        arrayList.add(object2);
        root.put("items", arrayList);
        return root.toJSONString();
    }

}
